package com.weihuachao.app;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.weihuachao.entity.Work;
import com.weihuachao.repair.R;

import java.util.List;

/**
 * Created by Virgo on 2016/7/31.
 */
public class WorkAdapter extends ArrayAdapter<Work> {
    private int resourceId;

    public WorkAdapter(Context context, int textViewResourceId, List<Work> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        Work work = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        TextView textView = (TextView) view.findViewById(R.id.text);
        ImageView imageView = (ImageView) view.findViewById(R.id.image);
        textView.setText(work.getTitle());
        if (work.getState() == 1) {
            imageView.setImageResource(R.drawable.ok);
        } else {
            imageView.setImageResource(R.drawable.no);
        }
        return view;
    }
}
